<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="jquery/jquery-1.10.2.js"></script>
<script type="text/javascript" src="md5/md5.js"></script>
	<style type="text/css">
	</style>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#submit").click(function(){
				var form = document.getElementById("loginForm");
				form.password.value=MD5.hex_md5(form.password.value);
				$.ajax({
					url:"http://127.0.0.1:8081/api/login",
					type:"POST",
					data:$("form").serialize(),
					success:function(r){
						console.log(r);
						alert(r.message);
					}
				});
			});
		});
		function doAjax(method,url,parm){
			$.ajax({
				url:url,
				type:method,
				data:parm,
				success:function(r){
					console.log(r);
					$("#resultTextarea").val(JSON.stringify(r));
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					console.log(XMLHttpRequest.responseText);
					$("#resultTextarea").val(XMLHttpRequest.responseText);
				}
			});
		}
		function doJsonAjax(method,url,parm){
			$.ajax({
				url:url,
				type:method,
				contentType:"application/json",
				data:JSON.stringify(parm),
				success:function(r){
					console.log(r);
					$("#resultTextarea").val(JSON.stringify(r));
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					console.log(XMLHttpRequest.responseText);
					$("#resultTextarea").val(XMLHttpRequest.responseText);
				}
			});
		}
	</script>
</head>
<style type="text/css">
.table{
	border-collapse:collapse;
	width:700px;
}
.table td,.table th{
	border:1px solid #ccc;
}
</style>
<body>
	<form id="loginForm" method="post">
		<input type="text" name="clientId" value="pcbrowser"></input>
		<input type="text" name="resource" value="pc"></input>
		<input type="text" name="clientVersion" value="1.0"></input>
		<input type="text" name="username" value="admin"></input>
		<input type="password" name="password" value="admin"></input>
		<input type="checkbox" id="rememberMe" name="rememberMe" value="remember-me">记住我（公共场所慎用）
		<input id="submit" type="button" value="登录"></input>
	</form>
	<h3>API列表（如果点击执行按钮时候提示会话过期，则点击上面的登录）</h3>
	<h4>访问api需要cookie中存在登录后的会话id，如：JSESSIONID=4f0cf552-e4de-43bd-99bb-c8a142f48446</h4>
	<table class="table" style="width:95%;">
		<tr>
			<th>api名称</th>
			<th>访问路径</th>
			<th>获取方式</th>
			<th>参数</th>
			<th>操作</th>
		</tr>
		<tr>
			<td colspan="5" style="font-weight:bold;text-align:center;">demo</td>
		</tr>
		<tr>
			<td>测试DELETE</td>
			<td>禁用了PUT，DELETE，HEAD，OPTIONS，TRACE等方法，这是一个测试</td>
			<td>GET</td>
			<td>无</td>
			<td><input type="button" value="执行" onclick="doAjax('DELETE','http://127.0.0.1:8081/admin/uom/user/uom_choose_test')"/></td>
		</tr>
		<tr>
			<td>测试demo</td>
			<td>http://127.0.0.1:8081/api/anon/demo</td>
			<td>GET</td>
			<td>无</td>
			<td><input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/anon/demo2')"/></td>
		</tr>
		<tr>
			<td colspan="5" style="font-weight:bold;text-align:center;">登录相关</td>
		</tr>
		<tr>
			<td>api登录</td>
			<td>http://127.0.0.1:8081/login?api_login=true</td>
			<td>POST</td>
			<td><a href="#login_api">详情</a></td>
			<td>demo演示见最顶端登录</td>
		</tr>
		<tr>
			<td>注销</td>
			<td>http://127.0.0.1:8081/logout?api_login=true</td>
			<td>POST</td>
			<td>无</td>
			<td></td>
		</tr>
		<tr>
			<td>根据token登录</td>
			<td>http://127.0.0.1:8081/api/login/token</td>
			<td>GET/POST</td>
			<td><a href="#login_token_api">详情</a></td>
			<td><input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/login/token?token=00014338a9677700')"/></td>
		</tr>
		<tr>
			<td>根据sessionId将其写入cookie</td>
			<td>http://127.0.0.1:8081/api/login/touch</td>
			<td>GET/POST</td>
			<td>jsessionId</td>
			<td></td>
		</tr>
		<tr>
			<td colspan="5" style="font-weight:bold;text-align:center;">用户</td>
		</tr>
		<tr>
			<td>保存用户信息</td>
			<td>http://127.0.0.1:8081/api/user/set_info</td>
			<td>PUT</td>
			<td>{
			<br>
			name:"xxx",//(不能为空)<br></br>
			gender:"0/1",//(不能为空)<br></br>
			password:"xxx",//(为空则为不修改)<br></br>
			email:"xxx",<br></br>
			phone:"xxx",<br></br>
			userInfo:{
				photo:"xxx",//图像url<br></br>
				shortNum:"xxx",//短号<br></br>
				workTel:"xxx",//办公电话<br></br>
				homeTel:"xxx",//家庭电话<br></br>
				addr:"xxx",//通讯地址<br></br>
				postCode:"xxx",//邮政编码<br></br>
				remark:"xxx"//备注说明<br></br>
			}
			}</td>
			<td><input type="button" value="执行" onclick="doJsonAjax('PUT','http://127.0.0.1:8081/api/user/set_info',{name:'Admin'+Math.floor(Math.random()*10+1),gender:'1',password:'admin',email:'admin'+Math.floor(Math.random()*10+1)+'@szcomtop.com',phone:'110',userInfo:{photo:'000001'}})"/></td>
		</tr>
		<tr>
			<td>获取当前登录用户信息</td>
			<td>http://127.0.0.1:8081/api/user/get_info</td>
			<td>GET</td>
			<td>无</td>
			<td><input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/user/get_info')"/></td>
		</tr>
		<tr>
			<td>获取指定帐号用户信息</td>
			<td>http://127.0.0.1:8081/api/user/get_info/{account}</td>
			<td>GET</td>
			<td>无</td>
			<td><input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/user/get_info/macccc')"/></td>
		</tr>
		<tr>
			<td>获取所有用户</td>
			<td>http://127.0.0.1:8081/api/user/find_users</td>
			<td>GET</td>
			<td>无</td>
			<td><input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/user/find_users')"/></td>
		</tr>
		<tr>
			<td colspan="5" style="font-weight:bold;text-align:center;">便签</td>
		</tr>
		<tr>
			<td>获取用户便签</td>
			<td>
				json格式: http://127.0.0.1:8081/api/memo<br></br>
				html格式: http://127.0.0.1:8081/memo
			</td>
			<td>GET</td>
			<td>无</td>
			<td>
				<input type="button" value="json执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/memo')"/><br></br>
				<input type="button" value="html执行" onclick="window.open('http://127.0.0.1:8081/memo');"/>
			</td>
		</tr>
		<tr>
			<td>保存用户便签</td>
			<td>http://127.0.0.1:8081/api/memo</td>
			<td>PUT</td>
			<td>{"memoId":"xxx" 必填,<br></br>"content":"xxxx" 非必填}</td>
			<td><input type="button" value="执行" onclick="doJsonAjax('PUT','http://127.0.0.1:8081/api/memo',{memoId:'0001435238862001',content:'测试的值'+(new Date()).getTime()})"/></td>
		</tr>
		<tr>
			<td colspan="5" style="font-weight:bold;text-align:center;">系统全局API</td>
		</tr>
		<tr>
			<td>IP设置服务</td>
			<td>
				http://127.0.0.1:8081/api/sys/ip_setting
			</td>
			<td>GET</td>
			<td>无</td>
			<td>
				<input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/sys/ip_setting')"/><br></br>
			</td>
		</tr>
		<tr>
			<td>系统初始化参数</td>
			<td>http://127.0.0.1:8081/api/sys/init_config</td>
			<td>GET</td>
			<td>无</td>
			<td><input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/api/sys/init_config')"/></td>
		</tr>
		<tr>
			<td colspan="5" style="font-weight:bold;text-align:center;">openAPI demo</td>
		</tr>
		<tr>
			<td>openApi get_userinfo</td>
			<td>
				http://127.0.0.1:8081/open/test/get_userinfo
			</td>
			<td>GET</td>
			<td>无</td>
			<td>
				<input type="button" value="执行" onclick="doAjax('GET','http://127.0.0.1:8081/open/test/get_userinfo?app_id=appid_00001&access_token=c44a73b8989aa076adc443152321388d',{userId:'0001'})"/><br></br>
			</td>
		</tr>
		<tr>
			<td>openApi set_userinfo form提交只能post/get</td>
			<td>
				http://127.0.0.1:8081/open/test/set_userinfo
			</td>
			<td>POST</td>
			<td>无</td>
			<td>
				<input type="button" value="执行" onclick="doAjax('POST','http://127.0.0.1:8081/open/test/set_userinfo?app_id=appid_00001&access_token=c44a73b8989aa076adc443152321388d',{userId:'0001',userName:'macongTest',email:'macongTest@szcomtop.com'})"/><br></br>
			</td>
		</tr>
		<tr>
			<td>save test</td>
			<td>
				http://127.0.0.1:8081/admin/uom/user/test/save
			</td>
			<td>GET</td>
			<td>无</td>
			<td>
				<input type="button" value="执行" onclick="doAjax('POST','http://127.0.0.1:8081/admin/uom/user/test/save?type=0')"/><br></br>
			</td>
		</tr>
		<tr>
			<td>wb回执</td>
			<td>
				http://127.0.0.1:8081/api/wb/sync/receipt
			</td>
			<td>GET</td>
			<td>无</td>
			<td>
				<input type="button" value="执行" onclick="doAjax('POST','http://127.0.0.1:8081/api/wb/sync/receipt?ver=61')"/><br></br>
			</td>
		</tr>
	</table>
	<h3>返回结果</h3>
	<textarea id="resultTextarea" rows="8" style="width:95%;"></textarea>
	<br></br>
	<br></br>
	<hr></hr>
	<h2>状态码说明</h2>
	<h3>状态码总体说明</h3>
	<ul>
		<li>state = 0: 正确返回</li>
		<li>state > 0: 调用API时发生错误，需要调用方进行相应的处理。</li>
		<li>-50 <= state <= -1: 接口调用不能通过接口代理机校验，需要开发者进行相应的处理</li>
		<li>state <-50: 系统内部错误</li>
	</ul>
	<h3>公共状态码说明</h3>
	<table class="table">
		<tr>
			<th>状态码</th>
			<th>说明</th>
		</tr>
		<tr><td>0</td><td>正确返回</td></tr>
		<tr><td>300</td><td>调用失败</td></tr>
		<tr><td>301</td><td>session超时</td></tr>
		<tr><td>403</td><td>禁止访问</td></tr>
		<tr><td>404</td><td>路径未找到</td></tr>
		<tr><td>500</td><td>服务器端错误</td></tr>
		<tr><td>1000</td><td>未知帐号</td></tr>
		<tr><td>1001</td><td>密码错误</td></tr>
		<tr><td>1002</td><td>帐号被冻结</td></tr>
		<tr><td>1003</td><td>验证码错误</td></tr>
		<tr><td>1004</td><td>认证失败</td></tr>
		<tr><td>1005</td><td>客户端id未指定</td></tr>
	</table>
	
	<br></br>
	<br></br>
	<hr></hr>
	<h2 id="login_api">登录</h2>
	<h3>URL</h3>"http://127.0.0.1:8081/login?api_login=true"
	<h3>HTTP请求方式</h3>POST
	<h3>请求参数</h3>
	<table class="table">
		<tr>
			<th>参数名</th>
			<th>必选</th>
			<th>类型</th>
			<th>说明</th>
		</tr>
		<tr>
			<td>clientId</td>
			<td>true</td>
			<td>String</td>
			<td>客户端设备id，每台终端设备唯一。web浏览器端登录默认为"pcbrowser"</td>
		</tr>
		<tr>
			<td>username</td>
			<td>true</td>
			<td>String</td>
			<td>登录帐号</td>
		</tr>
		<tr>
			<td>password</td>
			<td>true</td>
			<td>String</td>
			<td>登录密码(为了避免密码明文，需要为md5加密后的值)</td>
		</tr>
		<tr>
			<td>rememberMe</td>
			<td>false</td>
			<td>boolean</td>
			<td>记住登录状态</td>
		</tr>
		<tr>
			<td>captchaCode</td>
			<td>false</td>
			<td>String</td>
			<td>验证码(是否需要登录验证码，可以在服务端设置)</td>
		</tr>
	</table>
	<h3>返回</h3>
	<table class="table">
		<tr>
			<th>属性名</th>
			<th>类型</th>
			<th>说明</th>
		</tr>
		<tr>
			<td>state</td>
			<td>int</td>
			<td>状态码 </td>
		</tr>
		<tr>
			<td>message</td>
			<td>String</td>
			<td>消息	       成功:"登录成功"/失败:"登录失败"/session超时:"会话过期，请重新登录。"</td>
		</tr>
		<tr>
			<td>data</td>
			<td>Object</td>
			<td>数据	       成功:{"jsessionId":"xxxxxx","token":"xxxxx","userId":"xxxxx"}/失败:""/session超时:""</td>
		</tr>
	</table>
	<br></br>
	<br></br>
	<hr></hr>
	<h2 id="login_token_api">根据token登录</h2>
	<h3>URL</h3>"http://127.0.0.1:8081/api/login/token"
	<h3>HTTP请求方式</h3>GET/POST
	<h3>请求参数</h3>
	<table class="table">
		<tr>
			<th>参数名</th>
			<th>必选</th>
			<th>类型</th>
			<th>说明</th>
		</tr>
		<tr>
			<td>token</td>
			<td>true</td>
			<td>String</td>
			<td>登录时候传递给客户端的tokenId</td>
		</tr>
	</table>
	<h3>返回</h3>
	<table class="table">
		<tr>
			<th>属性名</th>
			<th>类型</th>
			<th>说明</th>
		</tr>
		<tr>
			<td>state</td>
			<td>int</td>
			<td>状态码</td>
		</tr>
		<tr>
			<td>message</td>
			<td>String</td>
			<td>消息	       成功:"根据token登录成功！"/失败:"token无效或过期"/session超时:"会话过期，请重新登录。"</td>
		</tr>
		<tr>
			<td>data</td>
			<td>Object</td>
			<td>数据	       成功:{"jsessionId":"xxxxxx","token":"xxxxx","userId":"xxxxx"}/失败:"tokenIllegal"/session超时:""</td>
		</tr>
	</table>
	<br></br>
	<br></br>
	<hr></hr>
	<h2>api调用测试</h2>
	<h3>URL</h3>"http://127.0.0.1:8081/api/anon/demo"
	<h3>HTTP请求方式</h3>GET/POST
	<h3>请求参数</h3>
	<table class="table">
		<tr>
			<th>参数名</th>
			<th>必选</th>
			<th>类型</th>
			<th>说明</th>
		</tr>
		<tr>
			<td>testStr</td>
			<td>false</td>
			<td>String</td>
			<td>传递测试字符串</td>
		</tr>
	</table>
	<h3>返回</h3>
	<table class="table">
		<tr>
			<th>属性名</th>
			<th>类型</th>
			<th>说明</th>
		</tr>
		<tr>
			<td>state</td>
			<td>int</td>
			<td>状态码 </td>
		</tr>
		<tr>
			<td>message</td>
			<td>String</td>
			<td>消息	       成功:"这是一个例子"/失败:""或其他/session超时:"会话过期，请重新登录。"</td>
		</tr>
		<tr>
			<td>data</td>
			<td>Object</td>
			<td>数据	       成功:"testStr字符串，也就是传入参数"/失败:""/session超时:""</td>
		</tr>
	</table>
	
</body>
</html>
